import Message from './Message.vue'
import { createApp } from 'vue'
export type MessageType = 'success' | 'error' | 'default'

const createMessage = (mess: string, type: MessageType, timeout = 2000) => {
  const MessageApp = createApp(Message, { // 创建message 组件实例，第二个参数为props
    mess,
    type
  })
  // 创建一个节点， 把实例挂载到节点上
  const divNode = document.createElement('div')
  document.body.appendChild(divNode)
  MessageApp.mount(divNode) // mount 挂载
  // 定时器。 多少时间消失
  setTimeout(() => {
    MessageApp.unmount() // unmount 卸载
    document.body.removeChild(divNode)
  }, timeout)
}

export default createMessage
